// The Swift Programming Language
// https://docs.swift.org/swift-book
import Raylib


func main() {
    Raylib.initAudioDevice()
    let width: Int32 = 800
    let height: Int32 = 600
    Raylib.initWindow(width, height, "My Game")
    Raylib.setTargetFPS(60)
    let randomColors: [Color] = [.blue, .red, .green, .yellow, .darkBlue, .maroon, .magenta]
    var ballColor: Color = .maroon
    var ballPosition = Vector2(x: -100, y: -100)
    var previousBallPosition: Vector2
    // Not support mp3 format 
    let beepSound = Raylib.loadSound("./zxing_beep.ogg")
    Raylib.playSound(beepSound)

    /* let music = Raylib.loadMusicStream("./zxing_beep.ogg") */
    /* Raylib.playMusicStream(music) */

    while Raylib.windowShouldClose == false {
        // update
        previousBallPosition = ballPosition
        ballPosition = Raylib.getMousePosition()
        if Raylib.isMouseButtonDown(.left) {
            ballColor = randomColors.randomElement() ?? .black
        }
        let size = max(abs(ballPosition.x - previousBallPosition.x) + abs(ballPosition.y - previousBallPosition.y), 10)

        // draw
        Raylib.beginDrawing()
        Raylib.clearBackground(.rayWhite)
        Raylib.drawText("Hello, world!", 425, 25, 25, .darkGray)
        Raylib.drawCircleV(ballPosition, size, ballColor)
        Raylib.drawFPS(10, 10)
        Raylib.endDrawing()
    }
    /* Raylib.unloadMusicStream(music) */
    Raylib.unloadSound(beepSound)
    Raylib.closeAudioDevice()
    Raylib.closeWindow()

}

main()
